﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ZLCMS.Business;
using ZLCMS.Business.DwzFrame;
using ZLCMS.Business.Util;
using ZLCMS.Data.Model;
using ZLCMS.Web.SystemManage.Control;
using System.Collections.Generic;
using NHibernate;
using DotNet.Common.TransferParam;
using NHibernate.Criterion;
using DotNet.Common.NHibernateUtil;

namespace ZLCMS.Web.SystemManage.Basics.Advert
{
    public partial class AdvertPositionEdit : System.Web.UI.Page
    {
        protected FrameHelper _framePage;
        protected ShopAdvertPositonInfo _advertDB;
        protected void Page_Load(object sender, EventArgs e)
        {
            //初始化全局变量值
            InitializeGlobalValue();

            //初始化控件值
            InitializeContent();
            //初始化DWZ控件

            _framePage = new FrameHelper(this);
            if (IsPostBack)
            {
                SaveBussines();
            }
        }

        private void InitializeGlobalValue()
        {
            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                try
                {
                    if (!IsPostBack)
                    {
                        _id.Text = Request["uid"];
                    }

                    _advertDB = session.Get<ShopAdvertPositonInfo>(_id.Text);

                    if (_advertDB == null)

                    {
                        throw new Exception("找不到对应信息.");
                    }
                }
                catch (System.Exception ex)
                {
                    _framePage.Alert(new ReturnCode() { statusCode = 300, message = "操作出错-" + ex.Message });
                    return;
                }
            }
        } 
        private void InitializeContent()
        {
            //页面控件值
            if (!IsPostBack)
            {
                txt_name.Text = _advertDB.Title;
            }
        }



        #region  +protected void AddBussines()
        /// <summary>
        /// 
        /// </summary>
        protected void SaveBussines()
        {
            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                _advertDB.Title = txt_name.Text;

                session.Update(_advertDB);
                session.Flush();
                 
                _framePage.Alert(new ReturnCode()
                {
                    statusCode = 200,
                    message = "操作成功!",
                    navTabId = _framePage.NavTabId
                });
            }
        }
        #endregion
    }
}